package com.example.community.service;

import com.example.community.entity.DiscussPost;
import com.example.community.entity.User;
import com.example.community.mapper.DiscussPostMapper;
import com.example.community.mapper.UserMapper;
import com.example.community.util.CommunityUitl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class DemoService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DiscussPostMapper discussPostMapper;

    @Transactional(isolation = Isolation.READ_COMMITTED)
    public Object savel(){
        // 新增用户
        User u = new User();
        u.setUsername("demo");
        u.setSalt(CommunityUitl.generateUUID().substring(0, 5));
        u.setPassword(CommunityUitl.md5("123" + u.getSalt()));
        u.setEmail("15656qq.com");
        u.setCreateTime(new Date());
        userMapper.insertUser(u);

        // 新增帖子
        DiscussPost post = new DiscussPost();
        post.setUserId(u.getId());
        post.setTitle("hello");
        post.setContent("新人报道！");
        post.setCreateTime(new Date());
        discussPostMapper.insertDiscussPost(post);

        Integer.valueOf("abc");

        return "ok";
    }
}

